package com.rop.znyx.common.auth;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * Created with IntelliJ IDEA
 * User: Rop
 * Date: 2023/7/19
 * Time: 11:14
 * Description:
 */

@Configuration
@RequiredArgsConstructor
public class LoginMvcConfigAdapter extends WebMvcConfigurationSupport {

    private final RedisTemplate<Object, Object> redisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加自定义拦截器，设置路径
        registry.addInterceptor(
                        new UserLoginInterceptor(redisTemplate))
                .addPathPatterns("/api/**")
                .excludePathPatterns("/api/user/weixin/wxLogin/*");
        super.addInterceptors(registry);
    }

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
        super.addResourceHandlers(registry);
    }
}
